#include <queue>
class Solution {
public:
    vector<int> GetLeastNumbers_Solution(vector<int>& nums, int k) {
        vector<int> res;
        if (nums.size() == 0 || k > nums.size() || k == 0) return res;
        priority_queue<int> q;
        for (int i = 0; i < k; ++i) {
            q.push(nums[i]);
        } 
        for (int i = k; i < nums.size(); i++) {
            if (nums[i] < q.top()) {
                q.pop();
                q.push(nums[i]);
            } 
        }
        while (!q.empty()) {
            res.push_back(q.top());
            q.pop();
        }
        return res;
    }
};